<?php
/**
 * Created by PhpStorm.
 * User: Kevin
 * Date: 2018/12/14
 * Time: 16:06
 */
namespace app\admin\controller;
use think\Db;
class About extends Base
{
    /**
     * 注册协议
     */
    public function agree(){
        if(request()->isAjax ()){
            extract(input());
            $lists = Db::name('about')
                ->where('a_id',1)
                ->select();
            return json(['code'=>220,'msg'=>'','count'=>'','data'=>$lists]);
        }
        return $this->fetch('about/agree');
    }

    /**
     * 编辑注册协议
     */
    public function agreeEdit(){
        if(request()->isPost ()){
            extract(input());
            $param = [
                'a_content'=>$content,
                'a_remark'=>$remark,
                'a_update_time'=>date('Y-m-d H:i:s')
            ];
            $res = Db::name('about')->where('a_id',$id)->update($param);
            if($res){
                return json(['code'=>200,'msg'=>"修改成功"]);
            }else{
                return json(['code'=>100,'msg'=>'修改失败']);
            }
        }
        $data = Db::name('about')->where('a_id',input('id'))->find();
        return $this->fetch('about/agree_edit',['data'=>$data]);
    }

    /**
     * 帮助
     */
    public function help(){
        if(request()->isAjax ()){
            extract(input());
            $lists = Db::name('about')
                ->where('a_id',2)
                ->select();
            return json(['code'=>220,'msg'=>'','count'=>'','data'=>$lists]);
        }
        return $this->fetch('about/help');
    }

    /*
     * 编辑帮助
     */
    public function helpEdit(){
        if(request()->isPost ()){
            extract(input());
            $param = [
                'a_content'=>$content,
                'a_remark'=>$remark,
                'a_update_time'=>date('Y-m-d H:i:s')
            ];
            $res = Db::name('about')->where('a_id',$id)->update($param);
            if($res){
                return json(['code'=>200,'msg'=>"修改成功"]);
            }else{
                return json(['code'=>100,'msg'=>'修改失败']);
            }
        }
        $data = Db::name('about')->where('a_id',input('id'))->find();
        return $this->fetch('about/help_edit',['data'=>$data]);
    }
}